//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.jeesite.modules.sys.wx.qy.util;


import com.jeesite.modules.sys.wx.qy.constants.Constants;
import net.sf.json.JSONObject;

public class MPerson {
    public static String CREATE_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=ACCESS_TOKEN";
    public static String UPDATA_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=ACCESS_TOKEN";
    public static String DELETE_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/delete?access_token=ACCESS_TOKEN&userid=ID";
    public static String BATCHDELETE_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete?access_token=ACCESS_TOKEN";
    public static String GET_PERSON_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&userid=USERID";
    public static String GET_GROUP_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID&fetch_child=FETCH_CHILD&status=STATUS";
    public static String GET_GROUPlIST_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID&fetch_child=FETCH_CHILD&status=STATUS";

    public MPerson() {
    }

    public static String CreateSimple(String userid, String name, String mobile,String department) {
        String PostData = "{\"userid\": \"%s\",\"name\": \"%s\",\"mobile\": \"%s\",\"department\": [" + department + "]";
        return String.format(PostData, new Object[]{userid, name, mobile, department});
    }

    public static String Create(String userid, String name, String mobile, String email, String department, String address, String corpName) {
        String PostData = "{\"userid\": \"%s\",\"name\": \"%s\",\"mobile\": \"%s\",\"email\": \"%s\",\"department\": [" + department + "],\"extattr\":{ \"attrs\":[{\"name\":\"地址\",\"value\":\"%s\"},{\"name\":\"企业名\",\"value\":\"%s\"}]}";
        return String.format(PostData, new Object[]{userid, name, mobile, email, department, address, corpName});
    }

    public static String Updata(String userid, String name, String position, String mobile, String email, String weixinid, String department, String enable) {
        String PostData = "{\"userid\": \"%s\",\"name\": \"%s\",\"position\": \"%s\",\"mobile\": \"%s\",\"email\": \"%s\",\"weixinid\": \"%s\",\"department\": [" + department + "],\"enable\":\"%s\"}";
        return String.format(PostData, new Object[]{userid, name, position, mobile, email, weixinid, department, enable});
    }

    public static String Delete(String userid) {
        String delete_url = DELETE_URL.replace("ID", userid);
        return delete_url;
    }

    public static String DeleteBatch(String lst) {
        String PostData = "{\"useridlist\": " + lst + "}";
        return String.format(PostData, new Object[0]);
    }

    public static String GPerson(String userid) {
        String getperson_url = GET_PERSON_URL.replace("ID", userid);
        return getperson_url;
    }

    public static String GPersonLst(String access_token, String department_id) {
        String getperson_url = GET_GROUPlIST_URL.replace("ACCESS_TOKEN", access_token).replace("DEPTID", department_id);
        return getperson_url;
    }

    public static String GGroup(String access_token, String department_id) {
        String getgroup_url = GET_GROUP_URL.replace("DEPTID", department_id).replace("ACCESS_TOKEN", access_token);
        return getgroup_url;
    }

    public static void main(String[] args) {
        String access_token = WeixinUtil.getAccessToken(Constants.CORPID, Constants.SECRETA).getToken();
        String out = Create("pianqu1_3", "张4", "", "13123366763", "", "", "7");
        CREATE_URL = CREATE_URL.replace("ACCESS_TOKEN", access_token);
        System.out.println(CREATE_URL);
        JSONObject jsonObject = WeixinUtil.HttpRequest(CREATE_URL, "POST", out);
        if(null != jsonObject) {
            System.out.println(jsonObject.toString());
        }

    }
}
